package cn.wolfcode.qo;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.util.List;

//封装分页查询结果的,
// 页面要展示的数据封装到这里
@Setter
@Getter
@ToString
public class PageResult<T> {
    //两个用户的输入
    private int currentPage; //查询当前页码
    private int pageSize; //查询每页显示的条数

    //两条SQL语句执行的结果
    private int totalCount;//查询总条数
    private List<T>data;//当前页结果集数据

    //三个程序计算的数据
    private int totalPage;//总页数
    private int prevPage;//上一页页码
    private int nextPage;//下一页页码

    //减少业务层枫叶实现的代码的重复
    public PageResult(int currentPage,int pageSize,int totalCount,List<T>data){

        this.currentPage = currentPage;
        this.pageSize = pageSize;

        this.totalCount = totalCount;
        this.data = data;

        //计算页数,上一页,下一页;
        //总页数
        this.totalPage = this.totalCount % this.pageSize == 0 ?
                this.totalCount / this.pageSize : this.totalCount / this.pageSize + 1;
        //上一页
        this.prevPage = this.currentPage - 1 >= 1 ? this.currentPage - 1 : 1;
        //下一页
        this.nextPage = this.currentPage + 1 <= this.totalPage ? this.currentPage + 1 : this.totalPage;

    }
}
